package com.atguigu.gulimail.seckill.vo;

import java.util.List;

/**
 * @author fangy
 * @date 2022-11-07 14:52
 */
public class consumer extends Thread{

    List<Integer> list;

    public consumer(List list) {

        this.list = list;

    }

    @Override
    public void run() {

        while (true) {

            synchronized (list) {

                if (list.size() == 1) {
                    try {
                        list.remove(0);
                        System.out.println("consumer,消费" + list.size());
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    list.notifyAll();
                }
                try {
                    list.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }

        }

    }

}
